package com.dv.web.controller.plan;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.driverless.domain.PlanWarehousing;
import com.dv.driverless.service.IPlanWarehousingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库计划Controller
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/plan/warehousing")
public class PlanWarehousingController extends BaseController
{
    @Autowired
    private IPlanWarehousingService planWarehousingService;

    /**
     * 查询入库计划列表
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlanWarehousing planWarehousing)
    {
        startPage();
        List<PlanWarehousing> list = planWarehousingService.selectPlanWarehousingList(planWarehousing);
        return getDataTable(list);
    }

    /**
     * 导出入库计划列表
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:export')")
    @Log(title = "入库计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanWarehousing planWarehousing)
    {
        List<PlanWarehousing> list = planWarehousingService.selectPlanWarehousingList(planWarehousing);
        ExcelUtil<PlanWarehousing> util = new ExcelUtil<PlanWarehousing>(PlanWarehousing.class);
        util.exportExcel(response, list, "入库计划数据");
    }

    /**
     * 获取入库计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(planWarehousingService.selectPlanWarehousingById(id));
    }

    /**
     * 新增入库计划
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:add')")
    @Log(title = "入库计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanWarehousing planWarehousing)
    {
        return toAjax(planWarehousingService.insertPlanWarehousing(planWarehousing));
    }

    /**
     * 修改入库计划
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:edit')")
    @Log(title = "入库计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanWarehousing planWarehousing)
    {
        return toAjax(planWarehousingService.updatePlanWarehousing(planWarehousing));
    }

    /**
     * 删除入库计划
     */
    @PreAuthorize("@ss.hasPermi('plan:warehousing:remove')")
    @Log(title = "入库计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planWarehousingService.deletePlanWarehousingByIds(ids));
    }
}
